package com.hdax.gulimall.order.service.impl;

import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.common.utils.PageUtils;
import com.hdax.common.utils.Query;

import com.hdax.gulimall.order.dao.MqMessageDao;
import com.hdax.gulimall.order.entity.MqMessageEntity;
import com.hdax.gulimall.order.service.MqMessageService;

import javax.swing.filechooser.FileSystemView;


@Service("mqMessageService")
public class MqMessageServiceImpl extends ServiceImpl<MqMessageDao, MqMessageEntity> implements MqMessageService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MqMessageEntity> page = this.page(
                new Query<MqMessageEntity>().getPage(params),
                new QueryWrapper<MqMessageEntity>()
        );

        return new PageUtils(page);
    }


    /**
     * 监听消息
     * queues:声明需要监听的所有队列
     */
//    @RabbitHandler：只可以标记在方法上
//    @RabbitListener:可以标记在类和方法上
    @RabbitListener(queues = {"hello.java"})
    public void rabbitLisner(Object message) {
        FileSystemView fsv = FileSystemView.getFileSystemView();
        File path=fsv.getHomeDirectory();
        System.out.println(path);
        try {
            File.createTempFile(String.valueOf(message), ".txt", path);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        System.out.println("接收到的消息内容："+message);
    }







}